import get from '@dfeidao/atom-web/local/get';
import remove from '@dfeidao/atom-web/local/remove';
import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';
import hide_loading from '../../atom/hide-loading';
import show_loading from '../../atom/show-loading';
import P01 from './P01';
import P02 from './P02';
import P03 from './P03';
import P04 from './P04';
import P05 from './P05';
// import { send_msg as url } from './config';
import P06 from './P06';

interface Aa {
	role_no: string;
}

export default async function a004(fd: IFeidaoAiBrowserComponent) {
	const search_field_val = fd.data.node.querySelector<HTMLInputElement>('#search_field_val').value;
	const productid = get(fd, 'productid');
	const page_no = 1;
	const page_size = get(fd, 'page_size') as number;
	set(fd, 'page_no', page_no);
	const role = get(fd, 'role') as Aa;
	show_loading();
	const res = await nodejs<{ dataArray: object[], count: number, page_no: number, page_size: number }>('roler/zj-000004/s005', { productid, role_no: role.role_no, search_field_val, page_no, page_size });
	hide_loading();
	if (res.count === 0) {
		render(fd, '', P01, 'P01', 'inner');
		fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="P05"]').innerHTML = '';
		render(fd, '', P04, 'P04', 'inner');
	} else {
		fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="P04"]').innerHTML = '';
		render(fd, res.dataArray, P01, 'P01', 'inner');
		res.page_no = page_no;
		res.page_size = page_size;
		render(fd, res, P05, 'P05', 'inner');
	}
	render(fd, '', P02, 'P02', 'inner');
	render(fd, '', P03, 'P03', 'inner');
	render(fd, '', P06, 'P06', 'inner');
	remove(fd, 'role_allot_id');
	remove(fd, 'allot_group');
	remove(fd, 'shezhi');
}
